import requests

# url定义成一个变量
url = "https://mall.deyunce.com/api/account/login"

# 写请求头授权 文本格式声明
head = {
    "authorization": "Basic ZGV5dW5jZTo4MjgxMjM=",
    "content-type": "application/json"
}

body = {"account": "18895747832", "password": "dxy123..456", "client": 5}

# 发送一个首页的接口，发送结果赋值给变量res
res = requests.post(url=url, headers=head, json=body)
# token = res.json()["data"]["token"]
# 打印状态码返回信息
# print(res.status_code)
# print(res.json())
# print(token)
# token加入head中
# head["token"] = token
# print(head)

url2 = "https://mall.deyunce.com/api/service/lists"
res2 = requests.get(url=url2, headers=head)
# print(res2.json())

#断言
assert res2.status_code == 200
assert res2.json()["msg"] == "获取成功"
#输入搜索内容
url3 = "https://mall.deyunce.com/api/pc/goodsList"
search = input("输入查询的商品：")
body = {"page_size": 20, "name": "熊猫"}
res3 = requests.get(url=url3, headers=head, params=body)
gid = res3.json()["data"]["list"][1]["id"]
# print(res3.json())
# print(gid)
#商品详情id
url4 = "https://mall.deyunce.com/api/goods/getGoodsDetail"
res4 = requests.get(url=url4,headers=head,params={"id":gid})
print(res4.json())
itemid = res4.json()["data"]["goods_item"][0]["id"]
# print(itemid)

#bug接口发送item_id
url5 = "https://mall.deyunce.com/api/order/buy"
body = {"action":"submit","goods":[{"item_id":356,"num":1}],"delivery_type":1}
res5 = requests.post(url=url5,headers=head,json=body)
print(res5.json())